#include <iostream>
#include <unordered_map>
#include <list>

class EfficientDataStructure {
private:
    std::unordered_map<int, std::list<int>::iterator> umap;
    std::list<int> elements;

public:
    void insert(int value) {
        if (umap.find(value) == umap.end()) {
            elements.push_front(value);
            umap[value] = elements.begin();
        }
    }

    void remove(int value) {
        if (umap.find(value) != umap.end()) {
            elements.erase(umap[value]);
            umap.erase(value);
        }
    }

    int getByIndex(int index) {
        if (index >= 0 && index < elements.size()) {
            auto it = elements.begin();
            std::advance(it, index);
            return *it;
        } else {
            return -1; 
        }
    }

};

int main() {
    EfficientDataStructure ds;

    ds.insert(1);
    ds.insert(2);
    ds.insert(3);

    std::cout << "Element at index 1: " << ds.getByIndex(1) << std::endl;
    std::cout << "Element at index 0: " << ds.getByIndex(0) << std::endl;

    ds.remove(2);

    std::cout << "Element at index 1 after removal: " << ds.getByIndex(1) << std::endl;

    return 0;
}